<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="职位管理页面">
<meta name="content-type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style type="text/css">
    body {
        width: 100%;
        height: 100%;
        background: #fff;
    }
    /*表格样式*/
    .table {
        margin-top: 50px;
    }
    /*按钮样式*/
    .btn_right {
        right: 10px;
        position: fixed;
    }
</style>
<link rel="stylesheet" href="/Hospital/lib/layui-v2.1.6/layui/css/layui.css" media="all">
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>病人信息管理</legend>
        <button id="btn_add" class="layui-btn btn_right">
            <i class="layui-icon">&#xe61f;</i> 添加
        </button>
    </fieldset>
    <table id="clientTable" class="layui-table table" style="margin-top: 50px" lay-filter="medicalListen"></table>
</body>
<script src="/Hospital/lib/jquery.min.js" charset="utf-8"></script>
<script src="/Hospital/lib/layui-v2.1.6/layui/layui.js" charset="utf-8"></script>
<script src="/Hospital/resources/js/util.js" charset="utf-8"></script>
<!--  具有编辑权限-->
<script type="text/html" id="bar1">
  <a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">详情</a>
  <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-mini" lay-event="check">病历</a>
  <a class="layui-btn layui-btn-mini" lay-event="checkMedicalCard">诊疗卡</a>
  <a class="layui-btn layui-btn-mini" lay-event="checkTreatInfo">治疗信息</a>
</script>
<!--  不具有编辑权限，具有查看权限-->
<script type="text/html" id="bar2">
  <a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">详情</a>
  <a class="layui-btn layui-btn-mini" lay-event="check">病历</a>
  <a class="layui-btn layui-btn-mini" lay-event="checkMedicalCard">诊疗卡</a>
  <a class="layui-btn layui-btn-mini" lay-event="checkTreatInfo">治疗信息</a>
</script>
<script type="text/javascript">
   var loginUser = JSON.parse(localStorage.getItem("loginUser"));
   
   var height=window.innerHeight*0.8;
   var columWidth=window.innerWidth*0.16;
   var normalWidth=window.innerWidth*0.2;
   var shortWidth=window.innerWidth*0.1;
   var longWidth=window.innerWidth*0.296;
   
   layui.use(["table","layer"],function () {
        var layer=layui.layer;
        var table=layui.table;
        var $=layui.jquery;
        initFrame();
        	
        function initFrame() {
        	if(loginUser.permission.createClient == 0) {	//如果不具有创建用户权限
        		//隐藏增加按钮
        		hide("#btn_add");
        	}
        	initTable();//初始化表格数据
            listen(); //监听事件
        }
        
        function initTable(){
            table.render({
                id:"clientTable",
                elem:"#clientTable",
                page:true,
                limit:10,
                center:true,
                height:height,
                cols:createCols(loginUser.permission),
                url:"/Hospital/userController/getClient",
                method:"POST",
                request : {
                	pageName: 'pageIndex', //页码的参数名称，默认：page
					limitName: 'pageSize' //每页数据量的参数名，默认：limit
	            },
                response:{
                	statusName:"code",
                	statusCode:200,
                	countName:"count",
                	msgName:"msg",
                	dataName:"result"
                }
            });
        }
   		function listen(){
   			$('#btn_add').click(function(){
   				layer.open({
   					title : '新增病人信息',
   					type : 2,
        			area : ['500px','590px'],
        			content : "/Hospital/views/medicalRecordManager/medicalRecordIframe.html",
        			btn : ['新增','取消'],
        			yes : function(layero,index){
        				var iframeWin = window[index.find('iframe')[0]['name']];
        				var isSuccess=iframeWin.submit();
        				if(isSuccess == 200){
        					initTable();
        					table.render();
        				}
        			}
   				});
   			});
   			table.on('tool(medicalListen)',function(obj){
            	var data=obj.data;
            	var layEvent=obj.event;
            	if(layEvent == 'detail'){		//点击详情按钮
            		localStorage.setItem("ClientData", JSON.stringify(data));
            		layer.open({
            			type : 2,
            			area : ['500px','590px'],
            			content : "/Hospital/views/medicalRecordManager/medicalRecordIframe.html",
            			cancel : function(index,layero){
            				localStorage.removeItem("ClientData");
            			}
            		});
            	}else if(layEvent == 'edit'){
            		localStorage.setItem("editClientData", JSON.stringify(data));
            		layer.open({
            			type : 2,
            			area : ['500px','590px'],
            			content : "/Hospital/views/medicalRecordManager/medicalRecordIframe.html",
            			cancel : function(index,layero){
            				localStorage.removeItem("editClientData");
            			},
            			btn : ["更改","取消"],
            			yes : function(index,layero){
            				console.log("medicalRecordTable.edit 更改按钮");
            				var iframeWin = window[layero.find('iframe')[0]['name']];
            				var isSuccess=iframeWin.updateSubmit();
            				if(isSuccess == 200){
            					initTable();
            					//table.render();
            					localStorage.removeItem("editClientData");
           						layer.close(index);
            				}
            			}
            		});
            	}else if(layEvent == 'check'){
            		var clientIdData={
            			"clientId" : data.clientId
            		};
            		localStorage.setItem("checkRecordClientId",JSON.stringify(clientIdData));
            		layer.open({
            			type : 2,
            			area : ['80%','90%'],
            			content : "/Hospital/views/medicalRecordManager/medicalRecordCheckIframe.html"
            		});
            	}else if(layEvent == 'checkMedicalCard'){
            		var data={
           				"clientId" : data.clientId
           			};
            		localStorage.setItem("medicalCardClientId", JSON.stringify(data));
            		layer.open({
            			type : 2,
            			area : ['80%','90%'],
            			content : "/Hospital/views/medicalRecordManager/medicalCard.html"
            		});
            	}else if(layEvent == 'checkTreatInfo'){
            		var data={
           				"clientId" : data.clientId
           			};
            		localStorage.setItem("treatInfoClientId", JSON.stringify(data));
            		layer.open({
            			type : 2,
            			area : ['80%','90%'],
            			content : "/Hospital/views/treatInfoManager/treatInfoTable.html"
            		});
            	}
            });
   		}
   });
   
 //生成表格的列
	function createCols(permission) {
		//console.log("clinicTable/createCols");
		if(permission.queryClient == 0) {	//不具有查看客户权限
			columWidth = window.innerWidth*0.198;
			cols = [[
	                    {field:'name',width:columWidth,title:'姓名',align:'center'},
	                    {field:'sex',width:columWidth,title:'性别',align:'center'},
	                    {field:'nation',width:columWidth,title:'民族',align:'center'},
	                    {field:'identity',width:columWidth,title:'身份证',align:'center'},
	                    {field:'status',width:columWidth,title:'客户类型',align:'center'},
	                ]];
			return cols;
		}else if(permission.alterClient == 0) {	//具备查看不具备编辑权限
			cols = [[
	                    {field:'name',width:normalWidth,title:'姓名',align:'center'},
	                    {field:'sex',width:shortWidth,title:'性别',align:'center'},
	                    {field:'nation',width:shortWidth,title:'民族',align:'center'},
	                    {field:'identity',width:normalWidth,title:'身份证',align:'center'},
	                    {field:'status',width:normalWidth,title:'客户类型',align:'center'},
	                    {fixed:'right',width:longWidth,align:'center',toolbar:'#bar2'}
	                ]];
			return cols;
		}
		//具备编辑权限包括不具备查看权限
		cols = [[
                    {field:'name',width:normalWidth,title:'姓名',align:'center'},
                    {field:'sex',width:shortWidth,title:'性别',align:'center'},
                    {field:'nation',width:shortWidth,title:'民族',align:'center'},
                    {field:'identity',width:normalWidth,title:'身份证',align:'center'},
                    {field:'status',width:normalWidth,title:'客户类型',align:'center'},
                    {fixed:'right',width:longWidth,align:'center',toolbar:'#bar1'}
                ]];
		return cols;
	}
</script>
</html>